<template>
  <div class="app-container">
    <div class="app-main">
      <div class="mainName">逾期上报</div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        class="search-form"
        label-width="100px"
      >
        <div class="search-row">
          <el-form-item label="任务单编号" prop="taskNumber">
            <el-input
              v-model="queryParams.taskNumber"
              placeholder="请输入"
              size="small"
              style="width: 180px"
            ></el-input>
          </el-form-item>
          <el-form-item label="信息来源" prop="source">
            <el-select
              v-model="queryParams.source"
              size="small"
              placeholder="请选择"
              clearable
              style="width: 180px"
            >
              <el-option
                v-for="item in sourceList"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="受理日期" prop="acceptanceDate">
            <el-date-picker
              v-model="queryParams.acceptanceDate"
              type="daterange"
              range-separator="-"
              start-placeholder="请选择开始时间"
              end-placeholder="请选择结束时间"
              size="small"
              style="width: 270px"
            ></el-date-picker>
          </el-form-item>
        </div>

        <div class="search-row">
          <el-form-item label="地址" prop="address">
            <el-input
              v-model="queryParams.address"
              placeholder="请输入"
              size="small"
              style="width: 180px"
            ></el-input>
          </el-form-item>
          <el-form-item label="单位名称" prop="companyName">
            <el-input
              v-model="queryParams.companyName"
              placeholder="请输入"
              size="small"
              style="width: 180px"
            ></el-input>
          </el-form-item>
          <el-form-item label="查勘日期" prop="surveyDate">
            <el-date-picker
              v-model="queryParams.surveyDate"
              type="daterange"
              range-separator="-"
              start-placeholder="请选择开始时间"
              end-placeholder="请选择结束时间"
              size="small"
              style="width: 270px"
            ></el-date-picker>
          </el-form-item>
        </div>

        <div class="search-row">
          <el-form-item label="联系人" prop="contactPerson">
            <el-input
              v-model="queryParams.contactPerson"
              placeholder="请输入"
              size="small"
              style="width: 180px"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系电话" prop="contactPhone">
            <el-input
              v-model="queryParams.contactPhone"
              placeholder="请输入"
              size="small"
              style="width: 180px"
            ></el-input>
          </el-form-item>
          <el-form-item label="施工日期" prop="constructionDate">
            <el-date-picker
              v-model="queryParams.constructionDate"
              type="daterange"
              range-separator="-"
              start-placeholder="请选择开始时间"
              end-placeholder="请选择结束时间"
              size="small"
              style="width: 270px"
            ></el-date-picker>
          </el-form-item>
          <el-form-item class="query-btn-item">
            <el-button type="primary" size="small" @click="handleQuery"
              >查询</el-button
            >
          </el-form-item>
        </div>
      </el-form>

      <el-table v-loading="loading" :data="list" border stripe>
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"
        ></el-table-column>
        <el-table-column
          label="任务单编号"
          align="center"
          prop="taskNumber"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
        <el-table-column
          label="白蚁防治企业名称"
          align="center"
          prop="companyName"
          :show-overflow-tooltip="true"
          min-width="180"
        ></el-table-column>
        <el-table-column
          label="受理日期"
          align="center"
          prop="acceptanceDate"
          :show-overflow-tooltip="true"
          min-width="100"
        ></el-table-column>
        <el-table-column
          label="查勘日期"
          align="center"
          prop="surveyDate"
          :show-overflow-tooltip="true"
          min-width="100"
        ></el-table-column>
        <el-table-column
          label="施工日期"
          align="center"
          prop="constructionDate"
          :show-overflow-tooltip="true"
          min-width="100"
        ></el-table-column>
        <el-table-column
          label="上报截止日期"
          align="center"
          prop="reportDeadline"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
        <el-table-column
          label="地址"
          align="center"
          prop="address"
          :show-overflow-tooltip="true"
          min-width="200"
        ></el-table-column>
        <el-table-column
          label="是否灭治"
          align="center"
          prop="isExterminated"
          :show-overflow-tooltip="true"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ scope.row.isExterminated ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column
          label="信息来源"
          align="center"
          prop="source"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
      />
    </div>

    <!-- 处理对话框 -->
    <el-dialog
      title="处理逾期上报"
      :visible.sync="open"
      width="600px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="单位名称" prop="companyName">
          <el-input v-model="form.companyName" disabled />
        </el-form-item>
        <el-form-item label="上报类型" prop="reportType">
          <el-input v-model="form.reportType" disabled />
        </el-form-item>
        <el-form-item label="处理结果" prop="handleResult">
          <el-input
            v-model="form.handleResult"
            type="textarea"
            placeholder="请输入处理结果"
            :rows="4"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入备注"
            :rows="3"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看对话框 -->
    <el-dialog
      title="查看详情"
      :visible.sync="viewOpen"
      width="600px"
      append-to-body
    >
      <el-form ref="viewForm" :model="viewForm" label-width="100px">
        <el-form-item label="单位名称">
          <el-input v-model="viewForm.companyName" disabled />
        </el-form-item>
        <el-form-item label="上报类型">
          <el-input v-model="viewForm.reportType" disabled />
        </el-form-item>
        <el-form-item label="应上报时间">
          <el-input v-model="viewForm.shouldReportTime" disabled />
        </el-form-item>
        <el-form-item label="逾期天数">
          <el-input v-model="viewForm.overdueDays" disabled />
        </el-form-item>
        <el-form-item label="联系人">
          <el-input v-model="viewForm.contactPerson" disabled />
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="viewForm.contactPhone" disabled />
        </el-form-item>
        <el-form-item label="处理结果">
          <el-input
            v-model="viewForm.handleResult"
            type="textarea"
            :rows="4"
            disabled
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="viewForm.remark"
            type="textarea"
            :rows="3"
            disabled
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "OverdueReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示查看弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskNumber: null,
        source: null,
        acceptanceDate: null,
        address: null,
        companyName: null,
        surveyDate: null,
        contactPerson: null,
        contactPhone: null,
        constructionDate: null,
      },
      // 表单参数
      form: {},
      // 查看表单参数
      viewForm: {},
      // 表单校验
      rules: {
        handleResult: [
          { required: true, message: "处理结果不能为空", trigger: "blur" },
        ],
      },
      // 信息来源列表
      sourceList: [
        { value: "企业自行受理", label: "企业自行受理" },
        { value: "962121受理", label: "962121受理" },
        { value: "其他", label: "其他" },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询逾期上报列表 */
    getList() {
      this.loading = true;
      // 模拟数据
      setTimeout(() => {
        this.list = [
          {
            id: 1,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "企业自行受理",
          },
          {
            id: 2,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "962121受理",
          },
          {
            id: 3,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "其他",
          },
          {
            id: 4,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "企业自行受理",
          },
          {
            id: 5,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "962121受理",
          },
          {
            id: 6,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "其他",
          },
          {
            id: 7,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "企业自行受理",
          },
          {
            id: 8,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "962121受理",
          },
          {
            id: 9,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "其他",
          },
          {
            id: 10,
            taskNumber: "250808281970",
            companyName: "黄浦区xx白蚁防治公司",
            acceptanceDate: "2025-06-20",
            surveyDate: "2025-06-22",
            constructionDate: "2025-06-26",
            reportDeadline: "2025-06-29",
            address: "上海市黄浦区xx弄xx号",
            isExterminated: true,
            source: "企业自行受理",
          },
        ];
        this.total = 446; // 设计稿显示总计446条记录
        this.loading = false;
      }, 1000);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 处理按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = Object.assign({}, row);
      this.open = true;
      this.title = "处理逾期上报";
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.viewForm = Object.assign({}, row);
      this.viewOpen = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 这里应该调用API接口
          this.$modal.msgSuccess("处理成功");
          this.open = false;
          this.getList();
        }
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: null,
        companyName: null,
        reportType: null,
        handleResult: null,
        remark: null,
      };
      this.resetForm("form");
    },
  },
};
</script>

<style scoped>
.app-container {
  /* padding: 20px; */
}

.app-main {
  background: #fff;
  padding: 20px;
  border-radius: 4px;
}

.mainName {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
  color: #303133;
}

.search-form {
  margin-bottom: 20px;
}

.search-row {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-row .el-form-item {
  margin-right: 20px;
  margin-bottom: 0;
}

.search-row .el-form-item__label {
  width: auto !important;
  text-align: left;
  padding-right: 8px;
}

.query-btn-item {
  margin-left: auto;
}

.query-btn-item .el-button {
  margin-left: 0;
}
</style>
